//
//  NDSmallCardListView.swift
//  NyamanDana
//
//  Created by 李永彬 on 2025/10/25.
//

import SwiftUI

struct NDSmallCardListView: View {
    let smallCardModel: PachistItem
    
    // 定义两列布局
    private let columns = [
        GridItem(.flexible(), spacing: 12),
        GridItem(.flexible(), spacing: 12)
    ]
    
    let onItemTapped: ((ProductListItem) -> Void)?
    
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            // 改为 LazyVGrid 实现两列布局
            ScrollView {
                LazyVGrid(columns: columns, spacing: 12) {
                    ForEach(Array(smallCardModel.productListItems.enumerated()), id: \.offset) { index, product in
                        NDSmallCardRow(product: product, isLast: index == smallCardModel.productListItems.count - 1)
                            .onTapGesture {
                                onItemTapped?(product)
                            }
                    }
                }
                .padding(.top, 1)
                .background(Color.clear)
                .padding(.horizontal, 24)
            }
        }
        .padding(.bottom, 50)
        .background(Color.clear)
    }
}

